#include "EngineHeader.h"
#include "GraphicsHeader.h"

namespace LSH
{
namespace Graphics
{

//------------------------------------------------------------------------------
Material::Material(void):_pTexture(0)
{
    memset(&_d3DMaterial, 0, sizeof(D3DMATERIAL9));
}

//------------------------------------------------------------------------------
Material::~Material(void)
{
}

//------------------------------------------------------------------------------
void Material::setAmbient(D3DCOLORVALUE& ambient)
{
    _d3DMaterial.Ambient = ambient;
}

//------------------------------------------------------------------------------
void Material::setDiffuse(D3DCOLORVALUE& diffuse)
{
    _d3DMaterial.Diffuse = diffuse;
}

//------------------------------------------------------------------------------
void Material::setSpecular(D3DCOLORVALUE& specular)
{
    _d3DMaterial.Specular = specular;
}

//------------------------------------------------------------------------------
void Material::setTexture(String& fileName)
{
    if(_pTexture != NULL)
    {
        TextureManager::getSingleton().freeTexture(_pTexture);
        _pTexture = NULL;
    }
    _pTexture = TextureManager::getSingleton().loadTextureFormFile(fileName);
}

//------------------------------------------------------------------------------
void Material::setTexture(Texture* pTexture)
{
    if(_pTexture != NULL)
    {
        TextureManager::getSingleton().freeTexture(_pTexture);
        _pTexture = NULL;
    }
    _pTexture = pTexture;
}

//------------------------------------------------------------------------------
D3DCOLORVALUE Material::getAmbient()
{
    return _d3DMaterial.Ambient;
}

//------------------------------------------------------------------------------
D3DCOLORVALUE Material::getDiffuse()
{
    return _d3DMaterial.Diffuse;
}

//------------------------------------------------------------------------------
D3DCOLORVALUE Material::getSpecular()
{
    return _d3DMaterial.Specular;
}

//------------------------------------------------------------------------------
Texture* Material::getTexture()
{
    return _pTexture;
}

//------------------------------------------------------------------------------
D3DMATERIAL9* Material::getMaterial()
{
    return &_d3DMaterial;
}

}
} // LSH
